package com.mt.baseinfo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mt.baseinfo.dao.resume.BaseDataDictDao;
import com.mt.baseinfo.entity.BaseDataDict;
import com.mt.baseinfo.enums.DataSourceType;
import com.mt.baseinfo.mult.DataSource;
import com.mt.baseinfo.service.BaseDataDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;

@Service
@DataSource(value = DataSourceType.DB1)
public class BaseDataDictServiceImpl extends ServiceImpl<BaseDataDictDao, BaseDataDict> implements BaseDataDictService {

    @Override
    public List<BaseDataDict> baseDataDicts() {
        QueryWrapper<BaseDataDict> wrapper = new QueryWrapper<>();
        List<BaseDataDict> baseDataDicts = baseMapper.selectList(wrapper);
        if(CollectionUtils.isEmpty(baseDataDicts)){
            return Collections.EMPTY_LIST;
        }
        return baseDataDicts;
    }

    @Override
    public int insertBaseDataDicts() {
        List<BaseDataDict> arryList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            BaseDataDict baseDataDict = new BaseDataDict();
            baseDataDict.setId(UUID.randomUUID().toString());
            baseDataDict.setCode("00"+i);
            baseDataDict.setName("A0"+i);
            arryList.add(baseDataDict);
        }

        return this.baseMapper.insertBatchSomeColumn(arryList);
    }
}
